#ifndef ZG_DATETIME_H
#define ZG_DATETIME_H

#include "ctime"
#include "sys/time.h"
#include "String.h"
#include <cstring>
#include "cstdio"
#include "iomanip"

#if __cplusplus >= 201103L
#include "chrono"
#endif

using std::string;
namespace zg_util{
    class DateTime{
    public:
        /* 当前日期字符串 e.g. 20170207*/
        static std::string CurDateStr();
        /*当前时间，标准mysql格式的时间*/
        static std::string CurDateTimeStr();
        /*当前带减号的日期，e.g. 2017-02-22*/
        static std::string CurDateStrSub();
        /* 当前日期小时字符串 e.g. 2017020709*/
        static std::string CurDateHourStr();
        /* 当前时间secs秒之前的日期小时字符串 e.g. 2017020709*/
        static std::string CurDateHourBeforeSecStr(int secs);
        static std::string CurMysqlDateBeforeSecStr(int secs);
        static std::string CurMysqlDateTimeBeforeSecStr(int secs);
        static std::string CurTimeStr();
        /* 当前小时字符串 e.g. 09*/
        static std::string CurHourStr();
        /* 当前天字符串 e.g. 09*/
        static std::string CurDayStr();
        /*解析标准的mysql时间戳*/
        static int ParseMysqltime(const std::string &mysql_time,int &year,int& mon,int& day,int &hour,int &min,int &sec);
        static int ParseDateStr(const std::string& str,int& year,int &mon,int& day,int& hour);

        static std::string FetchDateStr(const int year,const int mon,const int day,const int hour) ;
        /* 当前日期前days天字符串 e.g. 20170206*/
        static std::string DateStrBefore(int days=1);
        static long int CurUsec();
//#if __cplusplus >= 201103L
        template<typename T=std::chrono::time_point<std::chrono::system_clock,std::chrono::seconds> >
        static T MkTimePoint(int year,int mon,int day,int hour=0,int min=0,int sec=0){
                std::tm tm1;
                tm1.tm_year=year-1900;
                tm1.tm_mon=mon-1;
                tm1.tm_mday=day;
                tm1.tm_hour=hour;
                tm1.tm_min=min;
                tm1.tm_sec=sec;

                auto time_t1=std::mktime(&tm1);
                T t_p;
                t_p+=std::chrono::seconds(time_t1);
                return t_p;
        }
        template<typename T=std::chrono::time_point<std::chrono::system_clock,std::chrono::seconds> >
        static T MkTimePoint(std::tm &&t){
                auto time_t1=std::mktime(&t);
                T t_p;
                t_p+=std::chrono::seconds(time_t1);
                return t_p;
        }
        template<typename T=std::chrono::time_point<std::chrono::system_clock,std::chrono::seconds> >
        static T MkTimePoint(std::tm &t){
                auto time_t1=std::mktime(&t);
                T t_p;
                t_p+=std::chrono::seconds(time_t1);
                return t_p;
        };
        template<typename CharT,typename T=std::chrono::time_point<std::chrono::system_clock,std::chrono::seconds> >
        static T MkTimePoint(const string &date_time_str,const CharT* fmt){
                std::stringstream ss(date_time_str);
                std::tm tm1;
                ss>>std::get_time(&tm1,fmt);
                return MkTimePoint(tm1);
        };
//#endif
    private:

    };


}

#endif
